package sxe.core.hash;

import java.sql.SQLException;

import snobject.snNil;
import snobject.snObject;
import snobject.snObjectArgList;
import step.EvaluationFailure;
import step.FunctionWrapper;
import step.exceptions.ResourceUnavailableException;
import sxe.core.EvaluationFailureReasons;

public class remove extends FunctionWrapper {

	/* Usage (SNAFU style):
	 * 
	 * remove("key");
	 * 
	 * (non-Javadoc)
	 * @see step.FunctionWrapper#Call(snobject.snObjectArgList)
	 */
	
	@Override
	public snObject Call(snObjectArgList argv) throws EvaluationFailure,
			ClassCastException, ArrayIndexOutOfBoundsException, ResourceUnavailableException {

		snObject value = null;

		if(argv.length()<1)
			throw new EvaluationFailure(super.expnode,
					EvaluationFailureReasons.BAD_PARAMETER_COUNT);

		String key = argv.popString().getString();

		try{
			value = SQLClientInstance.getInstance().Remove(key);
			if (value==null) 
				return new snNil();
			return value;
		}
		catch(SQLException sqe){
			sqe.printStackTrace();
			throw new ResourceUnavailableException("SQLException in put: " + sqe.getMessage());
		}
	}

}
